/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.eventos.converters;

import org.cip.esymons.eventos.bc.PreeventoAdapter;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import org.cip.esymons.eventos.beans.PreEventoController;

/**
 *
 * @author lizardo
 */
public class CursoConverter implements Converter {
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
        if (arg2 == null) {
            return null;
        }
        Integer codigo = new Integer(arg2);
        PreEventoController controller = (PreEventoController) FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance(), "PreEventoController");
        return controller.buscarPorCodigo(codigo);
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
        if (arg2 == null) {
            return null;
        }
        if (arg2 instanceof PreeventoAdapter) {
            return ((PreeventoAdapter) arg2).getCodigo().toString();
        } else {
            return null;
        }
    }
}
